package com.qf.blogsystem.core.service.impl;

import com.qf.blogsystem.core.dao.BaseDao;
import com.qf.blogsystem.core.service.BaseService;

import java.util.List;

/**
 * @author Crazy
 * @version 1.0
 * @description: TODO
 * @date 2022/12/2 19:42
 */
public abstract class BaseServiceImpl<T> implements BaseService<T> {
    //获得dao实现类对象
    protected abstract BaseDao<T> getBaseDao();

    @Override
    public boolean save(T t) throws Exception {
        return getBaseDao().insert(t)>0;
    }

    @Override
    public boolean update(T t) throws Exception {
        return getBaseDao().updateById(t)>0;
    }

    @Override
    public boolean remove(Integer id) throws Exception {
        return getBaseDao().deleteById(id)>0;
    }

    @Override
    public T byId(Integer id) throws Exception {
        return getBaseDao().selectById(id);
    }

    @Override
    public List<T> list() throws Exception {
        return getBaseDao().selectList();
    }

    @Override
    public boolean batchRemove(List<Integer> ids) throws Exception {
        return getBaseDao().batchDelete(ids)>0;
    }
}
